package com.jinlia.show.modules.wxapp.service;

import com.jinlia.show.modules.base.constant.DataBoardTypeEnum;
import com.jinlia.show.modules.base.constant.DeliveryStatusEnum;
import com.jinlia.show.modules.base.system.entity.DeliveryOrder;
import com.jinlia.show.modules.base.system.service.DeliveryOrderMapperService;
import com.jinlia.show.modules.base.model.bo.DataBoardBO;
import com.jinlia.show.modules.base.wxapp.entity.PayOrder;
import com.jinlia.show.modules.base.wxapp.service.PayOrderMapperService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

/**
 * 工作台
 */
@Service
@RequiredArgsConstructor
public class WorkingTableService {
    @Autowired
    private DeliveryOrderMapperService deliveryOrderMapperService;
    @Autowired
    private PayOrderMapperService payOrderMapperService;
    /**
     * 构造数据看板
     *
     * @param dataBoardBOList
     * @return
     */
//    public List<DataBoardBO> getDataBoard(List<DataBoardBO> dataBoardBOList) {
//        //待办发货单
//        List<DeliveryOrder> list = null;
//        for (DataBoardBO dataBoardBO : dataBoardBOList) {
//            if (DataBoardTypeEnum.DATA_ORDER.equals(dataBoardBO.getDataBoardType())) {
//                //今日接单
//                Long count = deliveryOrderMapperService.lambdaQuery()
//                        .between(DeliveryOrder::getCreateTime, LocalDate.now(), LocalDate.now().plusDays(1))
//                        .ne(DeliveryOrder::getDeliveryStatus, DeliveryStatusEnum.INIT.getValue())
//                        .count();
//                dataBoardBO.setValue(Objects.isNull(count) ? "0" : String.valueOf(count));
//                continue;
//            }
//            if (DataBoardTypeEnum.DATA_PAY.equals(dataBoardBO.getDataBoardType())) {
//                //日收款
//                BigDecimal reduce = payOrderMapperService.lambdaQuery()
//                        .eq(PayOrder::getPayDate, LocalDate.now())
//                        .select(PayOrder::getId, PayOrder::getPaidAmount)
//                        .list().stream()
//                        .map(PayOrder::getPaidAmount)
//                        .reduce(BigDecimal.ZERO, BigDecimal::add);//求和
//                dataBoardBO.setValue(Objects.isNull(reduce) ? "0" : String.valueOf(reduce));
//                continue;
//            }
//            //---------------最后-----------------------
//            if (CollectionUtils.isEmpty(list)) {
//                list = deliveryOrderMapperService.lambdaQuery()
//                        .select(DeliveryOrder::getDeliveryStatus)
//                        .between(DeliveryOrder::getCreateTime, LocalDate.now(), LocalDate.now().plusDays(1))
//                        .ne(DeliveryOrder::getDeliveryStatus, DeliveryStatusEnum.INIT.getValue())
//                        .list();
//            }
//            if (DataBoardTypeEnum.WAIT_CONFIRM.equals(dataBoardBO.getDataBoardType())) {
//                //待接单
//                long count = list.stream().filter(i -> i.getDeliveryStatus().equals(DeliveryStatusEnum.WAIT_CONFIRM.getValue())).count();
//                dataBoardBO.setValue(Objects.isNull(count) ? "0.00" : String.valueOf(count));
//            }
//            if (DataBoardTypeEnum.PART_REFUND.equals(dataBoardBO.getDataBoardType())) {
//                //待接单
//                long count = list.stream().filter(i -> i.getDeliveryStatus().equals(DeliveryStatusEnum.WAIT_DELIVERY.getValue())).count();
//                dataBoardBO.setValue(Objects.isNull(count) ? "0.00" : String.valueOf(count));
//            } else if (DataBoardTypeEnum.ALL_REFUND.equals(dataBoardBO.getDataBoardType())) {
//                //在途中
//                long count = list.stream().filter(i -> i.getDeliveryStatus().equals(DeliveryStatusEnum.ON_WAY.getValue())).count();
//                dataBoardBO.setValue(Objects.isNull(count) ? "0.00" : String.valueOf(count));
//            } else if (DataBoardTypeEnum.ALL_REFUND2.equals(dataBoardBO.getDataBoardType())) {
//                //已完成
//                long count = list.stream()
//                        .filter(i -> i.getDeliveryStatus().equals(DeliveryStatusEnum.ARRIVED.getValue())  //已送达
//                                || i.getDeliveryStatus().equals(DeliveryStatusEnum.USER_CONFIRM.getValue())) //客户确认
//                        .count();
//                dataBoardBO.setValue(Objects.isNull(count) ? "0.00" : String.valueOf(count));
//            }
//        }
//        return dataBoardBOList;
//    }
}
